﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Data;
namespace canyinguanlixitong
{
    class DBHelper
    {
        public string strconn = "Data Source=.;Initial Catalog=Supermarket management system;Integrated Security=True";
        private SqlConnection connection;

        public SqlConnection Connection
        {
            get
            {
                if (connection == null)
                {
                    connection = new SqlConnection(strconn);
                }
                return connection;

            }
        }
        public void OpenConnection()
        {
            if (Connection.State == ConnectionState.Closed)
            {
                Connection.Open();
            }
            else if (Connection.State == ConnectionState.Broken)
            {
                Connection.Close();
                Connection.Open();
            }
        }
        public void CloceConnection()
        {
            if (Connection.State == ConnectionState.Open
                || Connection.State == ConnectionState.Broken)
            {
                Connection.Close();
            }
        }
    }
}
